package com.ellwood.IPGuard;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

/**
 * @ProjectName: IPGuard-boot
 * @PackageName: com.ellwood.IPGuard
 * @ClassName: IPGuardApplication
 * @Description: // 项目启动
 * @Author: Ellwood
 * @CreateDate: 2024/9/25 - 上午11:30
 * @Version: V1.0.0
 */
@Slf4j
@SpringBootApplication
public class IPGuardApplication extends SpringBootServletInitializer {

    @SneakyThrows
    public static void main(String[] args) {
        // 启动项目
        SpringApplication sa = new SpringApplication(IPGuardApplication.class);
        ConfigurableApplicationContext context = sa.run(args);
        Environment env = context.getEnvironment();
        log.info(
                "\n Ellwood-IPGuard-boot管理系统启动成功！！\n" +
                        "----------------------------------------------------------\\n\\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t" +
                        "Doc: \thttp://{}:{}/doc.html\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port")
        );
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder sab) {
        return sab.sources(IPGuardApplication.class);
    }

}
